const app = getApp();
Page({
  data: {
    isLoading: true,                    // 判断是否尚在加载中
    article: {},                     // 内容数据
    id: '',
    title: '',
    url: 'https://636c-cloud1-5gnxbga2f5eed8c0-1305796051.tcb.qcloud.la/image/location.png?sign=5e3126fc3a07553f3c5be508a1229d48&t=1622292387',
    place: {}
  },
  onLoad: function (options) {
    this.data.id = options.id
    const _this = this
    wx.cloud.callFunction({
      name: 'getPlaceById',
      data: {
        _id: _this.data.id,
      }
    }).then(res => {
      console.log(res)
      wx.setNavigationBarTitle({
        title: res.result.data.name,
      })
      let result = app.towxml(res.result.data.desc, 'markdown', {
        theme: 'light',                   // 主题，默认`light`
        events: {                    // 为元素绑定的事件方法
          tap: (e) => {
            console.log('tap', e);
          }
        }
      });
      // 更新解析数据
      _this.setData({
        title: res.result.data.name,
        article: result,
        isLoading: false,
        place: res.result.data
      });
    })
  },
  toPlace: function()
  {
    console.log(this.data.place)
    let endPoint = JSON.stringify({  //终点
      'name': this.data.place.name,
      'latitude': this.data.place.latitude,
      'longitude': this.data.place.longitude
    });
    wx.navigateTo({
      url: '/pages/routes/routes?endPoint='+ endPoint,
    })
  }
})